home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / properties.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  7KB  |  174 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, GObject, Pango
  5. from quodlibet import qltk
  6. from quodlibet import config
  7. from quodlibet.qltk.edittags import EditTags
  8. from quodlibet.qltk.renamefiles import RenameFiles
  9. from quodlibet.qltk.tagsfrompath import TagsFromPath
  10. from quodlibet.qltk.tracknumbers import TrackNumbers
  11. from quodlibet.qltk.views import HintedTreeView
  12. from quodlibet.qltk.window import PersistentWindowMixin
  13. from quodlibet.qltk.x import ScrolledWindow, ConfigRPaned
  14. from quodlibet.util.path import fsdecode
  15. from quodlibet.util import connect_obj, connect_destroy
  16.  
  17. class SongProperties(qltk.Window, PersistentWindowMixin):
  18.     __gsignals__ = {
  19.         'changed': (GObject.SignalFlags.RUN_LAST, None, (object,)) }
  20.     
  21.     def __init__(self, library, songs, parent = None):
  22.         super(SongProperties, self).__init__(dialog = False)
  23.         self.set_transient_for(qltk.get_top_parent(parent))
  24.         default_width = 600
  25.         config_suffix = ''
  26.         if len(songs) <= 1:
  27.             default_width -= 200
  28.             config_suffix += 'single'
  29.         self.set_default_size(default_width, 400)
  30.         self.enable_window_tracking('quodlibet_properties', size_suffix = config_suffix)
  31.         self.auto_save_on_change = config.getboolean('editing', 'auto_save_changes', False)
  32.         paned = ConfigRPaned('memory', 'quodlibet_properties_pos', 0.4)
  33.         notebook = qltk.Notebook()
  34.         notebook.props.scrollable = True
  35.         pages = []
  36.         pages.extend([ Ctr(self, library) for Ctr in [
  37.             EditTags,
  38.             TagsFromPath,
  39.             RenameFiles] ])
  40.         if len(songs) > 1:
  41.             pages.append(TrackNumbers(self, library))
  42.         for page in pages:
  43.             page.show()
  44.             notebook.append_page(page)
  45.         
  46.         fbasemodel = Gtk.ListStore(object, str)
  47.         fmodel = Gtk.TreeModelSort(model = fbasemodel)
  48.         fview = HintedTreeView(model = fmodel)
  49.         fview.connect('button-press-event', self._SongProperties__pre_selection_changed)
  50.         fview.set_rules_hint(True)
  51.         selection = fview.get_selection()
  52.         selection.set_mode(Gtk.SelectionMode.MULTIPLE)
  53.         self._SongProperties__save = None
  54.         if len(songs) > 1:
  55.             render = Gtk.CellRendererText()
  56.             c1 = Gtk.TreeViewColumn(_('File'), render, text = 1)
  57.             render.set_property('ellipsize', Pango.EllipsizeMode.END)
  58.             render.set_property('xpad', 3)
  59.             c1.set_sort_column_id(1)
  60.             fview.append_column(c1)
  61.             sw = ScrolledWindow()
  62.             sw.add(fview)
  63.             sw.set_shadow_type(Gtk.ShadowType.IN)
  64.             sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
  65.             sw.show_all()
  66.             paned.pack1(sw, shrink = False, resize = True)
  67.         for song in songs:
  68.             fbasemodel.append(row = [
  69.                 song,
  70.                 fsdecode(song('~basename'))])
  71.         
  72.         connect_obj(self, 'changed', SongProperties._SongProperties__set_title, self)
  73.         selection.select_all()
  74.         paned.pack2(notebook, shrink = False, resize = True)
  75.         csig = selection.connect('changed', self._SongProperties__selection_changed)
  76.         connect_destroy(library, 'changed', self._SongProperties__refresh, fbasemodel, fview)
  77.         connect_destroy(library, 'removed', self._SongProperties__remove, fbasemodel, selection, csig)
  78.         connect_obj(self, 'changed', self.set_pending, None)
  79.         self.emit('changed', songs)
  80.         self.add(paned)
  81.         paned.set_position(175)
  82.         notebook.show()
  83.         paned.show()
  84.  
  85.     
  86.     def __remove(self, library, songs, model, selection, sig):
  87.         selection.handler_block(sig)
  88.         if len(model) == 1:
  89.             rows = [
  90.                 Gtk.TreePath((0,))]
  91.         else:
  92.             rows = selection.get_selected_rows()[1]
  93.         to_remove = []
  94.         changed = False
  95.         for row in model:
  96.             if row[0] in songs:
  97.                 to_remove.append(row.iter)
  98.                 if not changed:
  99.                     pass
  100.             changed = row.path in rows
  101.             continue
  102.         
  103.         for iter_ in to_remove:
  104.             model.remove(iter_)
  105.         
  106.         selection.handler_unblock(sig)
  107.         if changed:
  108.             selection.emit('changed')
  109.  
  110.     
  111.     def __set_title(self, songs):
  112.         if songs:
  113.             if len(songs) == 1:
  114.                 title = songs[0].comma('title')
  115.             else:
  116.                 title = ngettext('%(title)s and %(count)d more', '%(title)s and %(count)d more', len(songs) - 1) % {
  117.                     'title': songs[0].comma('title'),
  118.                     'count': len(songs) - 1 }
  119.             self.set_title('%s - %s' % (title, _('Properties')))
  120.         else:
  121.             self.set_title(_('Properties'))
  122.  
  123.     
  124.     def __refresh(self, library, songs, model, view):
  125.         view.freeze_notify()
  126.         if len(model) == 1:
  127.             rows = [
  128.                 Gtk.TreePath((0,))]
  129.         else:
  130.             rows = view.get_selection().get_selected_rows()[1]
  131.         changed = False
  132.         for row in model:
  133.             song = row[0]
  134.             if song in songs:
  135.                 row[1] = song('~basename')
  136.                 if not changed:
  137.                     pass
  138.             changed = row.path in rows
  139.             continue
  140.         
  141.         view.thaw_notify()
  142.         if changed:
  143.             view.get_selection().emit('changed')
  144.  
  145.     
  146.     def set_pending(self, button, *excess):
  147.         self._SongProperties__save = button
  148.  
  149.     
  150.     def __pre_selection_changed(self, view, event):
  151.         if self._SongProperties__save:
  152.             if self.auto_save_on_change:
  153.                 self._SongProperties__save.clicked()
  154.                 return None
  155.             resp = None.CancelRevertSave(self).run()
  156.             if resp == Gtk.ResponseType.YES:
  157.                 self._SongProperties__save.clicked()
  158.             elif resp == Gtk.ResponseType.NO:
  159.                 return False
  160.             return True
  161.  
  162.     
  163.     def __selection_changed(self, selection):
  164.         model = selection.get_tree_view().get_model()
  165.         if len(model) == 1:
  166.             self.emit('changed', [
  167.                 model[(0,)][0]])
  168.         else:
  169.             (model, rows) = selection.get_selected_rows()
  170.             songs = [ model[row][0] for row in rows ]
  171.             self.emit('changed', songs)
  172.  
  173.  
  174.